package com.qingmeng.apiclientsdk.entry;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ApiResponse<T> {
    private boolean success;
    private String message;
    private T data;

    // 成功响应的静态方法
    public static <T> ApiResponse<T> success(T data) {
        return new ApiResponse<>(true, "操作成功", data);
    }

    public static <T> ApiResponse<T> success(String message, T data) {
        return new ApiResponse<>(true, message, data);
    }

    public static ApiResponse<Void> success() {
        return new ApiResponse<>(true, "操作成功", null);
    }

    // 失败响应的静态方法
    public static ApiResponse<Void> failure(String message) {
        return new ApiResponse<>(false, message, null);
    }

    public static ApiResponse<Void> failure(Throwable e) {
        return new ApiResponse<>(false, "操作失败: " + e.getMessage(), null);
    }
}
